<template>
  <!-- 导航tab -->
  <div class="classify-list">
    <div
      class="classify-item"
      v-for="(item, index) in classifyList"
      :key="index"
      @click.stop="handleTab(item, index)"
    >
      <p
        class="classify-name"
        :style="{
          color:
            active == index
              ? propsData.params.defaultTab.fontCss.color
              : propsData.params.subtitleTab.defaultTitleColor,
        }"
      >
        {{ item.title }}
      </p>
      <div
        class="active-box"
        :class="active == index ? 'active' : ''"
        :style="
          active == index
            ? 'background:' + propsData.params.defaultTab.activeColor
            : ''
        "
      ></div>
      <div class="item-hover" v-if="active == index">
        <div
          class="edit-box"
          @click.stop="
            handleClassifyTabItem('classifySubtitleControl', item, index)
          "
        >
          <i class="iconfont icon-mokuai-bianji"></i>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    propsData: {
      type: Object,
      default: {},
    },
    active: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {};
  },
  mounted() {},
  watch: {},
  computed: {
    classifyList() {
      if (this.propsData.params.classifyList.length <= 0) {
        let arr = [];
        for (let i = 0; i < 6; i++) {
          let obj = {
            title: "标题",
            subTitle: "副标题",
            link: null,
            data: null,
            dataFrom: "",
            classifyId: "",
          };
          arr.push(obj);
        }
        return arr;
      }

      return this.propsData.params.classifyList;
    },
  },
  methods: {
    // 点击切换tab
    handleTab(item, index) {
      this.$emit("changeTab", { item, index });
    },
    // 点击编辑当前状态
    handleClassifyTabItem(name, item, index) {
      this.handleTab(item, index);
      console.log("点击单个专题导航");
      let data = Object.assign({}, this.propsData);
      data.controlComName = name;
      this.$emit("handleClassifyTabItem", data);
    },
  },
};
</script>

<style lang="scss" scoped>
.classify-list {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  .classify-item {
    margin-right: 30px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    .classify-name {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 600;
      line-height: 22px;
      color: #262626;
      margin-bottom: 0;
    }
    .active-box {
      width: 100%;
      height: 3px;
      margin-top: 2px;
    }
    .active {
      background: #fa2c1b;
    }
    .item-hover {
      width: 100%;
      height: 100%;
      border: 1px solid #1890fc;
      position: absolute;
      left: 0;
      top: 0;
      display: none;
      .edit-box {
        width: 20px;
        height: 20px;
        background: #1890fc;
        border-radius: 0px 0px 0px 4px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        position: absolute;
        right: 0;
        top: 0;
        .iconfont {
          font-size: 18px;
          color: #ffffff;
        }
      }
    }
  }
  .classify-item:last-child {
    margin-right: 0;
  }
  .classify-item:hover > .item-hover {
    display: block;
  }
}
</style>
